/*
*   本文件属于Raiiwhen的个人库代码仓
*   cio.cpp & .h 用于维护私有二进制协议的环形队列，并向ctask注册回调任务
*
*   THIS PROGRAM IS FREE SOFTWARE WITH NO LIMIT, IS LICENSED UNDER BALABALA.LIC,
*   USE IT AS YOU WANT, AND BUY A COLA WHEN MET AUTHOR
*
*   Copyright (c) 2023 Raiiwhen masterraii@icloud.com
*/

#ifndef _CIO_H_
#define _CIO_H_

#include "../common_typedef.h"
#include "../frm_struct_def.h"

typedef int (*CioTaskCallback)(const char *, size_t);
typedef struct
{
    pkgType cmd;
    CioTaskCallback task;
} CioPair;

typedef enum
{
    CIO_RDY,
    CIO_PROCING, // 将缓存数据注册到任务回调
    CIO_OVF, // 队列溢出
} CioSta;
/* 初始化调用 */
void CioInit(CioPair* cioList, int cioListLen);
void CioRegisterRx(uint8_t* rxBuffer, uint8_t* rxBufMirror, size_t rxLen);
void CioRegisterTx(uint8_t* txBuffer, size_t txLen);
void CioDump(void);
int CioPrintRxBuffer(const char *str, size_t len);
/* 接收数据调用 */
uint32_t CioRxPkg(const uint8_t *pPkg, size_t len);
/* 发送数据包调用 */
uint32_t CioTxPkg(pkgType type, const void* src, uint32_t len);
/* 环形队列 */
void CioRstRx(void);
CioSta CioPush(size_t pushLen);
void CioPop(size_t PopLen);
CioSta GetCioSta(void);
FrmTransState ProcCioRxEvent(void);
/* 公共cio方法 */
void GenVerInfo(uint8_t* dst, size_t lenMax);

#endif // #ifndef _CIO_H_
